package com.shenmazong.demodelayqueuetask.service;

import com.shenmazong.demodelayqueuetask.utils.MqConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: server-java-demo
 * @description: ProcessService
 * @author: 亮子说编程
 * @create: 2020-11-02 16:11
 **/

@Slf4j
@Service
public class ProcessService {
    @Autowired
    private AmqpTemplate amqpTemplate;

    @RabbitListener(queues= MqConstant.MY_TRANS_QUEUE)
    @RabbitHandler
    public void process(String content) {
        String msg = content.split(":")[0];
        String delayQueueName = content.split(":")[1];
        amqpTemplate.convertAndSend(MqConstant.MY_EXCHANGE, delayQueueName, msg);
        log.info("进行转发 {}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }
}
